#ifndef __CRITICALSECTION_H__
#define __CRITICALSECTION_H__


#include "../SyncMethod/IMethod.h"


namespace Sync
{

class CriticalSection : public IMethod
{		
	CRITICAL_SECTION _cs;


public :
	CriticalSection( const char* sync_title ) : IMethod( sync_title ) {}
	virtual ~CriticalSection( void ) {}


	virtual void release( void ) override
	{
		DeleteCriticalSection( &_cs );
	}

	virtual void initialize( void ) override
	{
		InitializeCriticalSection( &_cs );

		std::cout << name().c_str() << std::endl;
	}

	virtual bool lock( void ) override
	{
		EnterCriticalSection( &_cs );

		return true;
	}

	virtual void unlock( void ) override
	{
		LeaveCriticalSection( &_cs );
	}
};

};

#endif